package jdbmaplite.connection.impl;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.Properties;

import jdbmaplite.connection.DBConnectionFactory;

public class BasicConnectionFactory extends DBConnectionFactory {

	private Properties properties = null;

	/**
	 * Default constructor.
	 * 
	 * @param driver
	 *            String
	 * @param url
	 *            String
	 * @param user
	 *            String
	 * @param password
	 *            String
	 * @throws ClassNotFoundException
	 */
	public BasicConnectionFactory(String driver, String url, String user,
			String password) throws ClassNotFoundException {
		super(driver, url, user, password);
		loadDriver();
	}

	public void loadProperties(Properties properties) {
		this.properties = properties;
		properties.setProperty("user", getUser());
		properties.setProperty("password", getPassword());
	}

	public Connection getConnection() throws SQLException {
		return DriverManager.getConnection(getUrl(), properties);
	}

	public void destroy() throws SQLException {
	}

	/**
	 * Load Driver
	 * 
	 * @throws ClassNotFoundException
	 */
	public void loadDriver() throws ClassNotFoundException {
		Class.forName(getDriver());
	}

	/**
	 * Get Properties
	 * 
	 * @return Properties
	 */
	public Properties getProperties() {
		return properties;
	}

	/**
	 * Set Properties
	 * 
	 * @param properties
	 *            Properties
	 */
	public void setProperties(Properties properties) {
		this.properties = properties;
	}

}